package rabbit.work;

import com.rabbitmq.client.Channel;
import rabbit.util.RabbitMqUtils;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Product
 * Package: rabbit.work
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-25
 * Time: 15:24
 */

public class Product {
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {

        //生产者 发送大量的消息
        Channel chanel = RabbitMqUtils.getChanel();
        //队列的声明
        chanel.queueDeclare(QUEUE_NAME,false,false,false,null);
        //发送消息
        //从控制台发送
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String next = scanner.next();
            //交换机 路由key 其他参数 消息体
            chanel.basicPublish("",QUEUE_NAME,null,next.getBytes());
            System.out.println("消息发送完成: " + next);
        }

    }

}
